package com.bjc.principle.absfactory.order;

import com.bjc.principle.absfactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @program: DesignPattern
 * @description:
 * @author: bjc
 * @create: 2020-12-16 21:04
 */
public class OrderPizza {

    AbsFactory factory;

    public OrderPizza(AbsFactory factory) {
        setFactory(factory);
    }

    private void setFactory(AbsFactory factory) {
        Pizza pizza = null;
        String orderType = "";//用户输入
        this.factory = factory;

        do {
            orderType = getType();
            pizza = factory.createPizza(orderType);
            if (pizza != null){ //订阅ok
                //输出披萨制作过程
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购失败");
                break;
            }
        }while (true);
    }

    //写一个方法，可以获取用户希望订购的披萨种类
    private String getType(){
        try{
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type");
            String s = strin.readLine();
            return s;
        }catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }
}
